// pages/input/i_index.js
var util=require("../../util/getTime.js")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        formdata:{
            container:''
        },
        userdata:{}

    },
    onShow() {
        var that=this;
        wx.getStorage({
            key: 'userdata',
            success(res) {
                that.setData({
                    'userdata':res.data
                })
            }
        });
    },
    bindTextAreaBlur: function(e) {
        this.setData({
            'formdata.container':e.detail.value
        }) 

     },    
     formSubmit: function(e) {
        var formdata=this.data.formdata;
        if(formdata==''||formdata.container==''){
            wx.showToast({
              title: '请输入你想说的话',
              icon:"error"
            })
        }else{
            var time=util.formatTime(new Date())
            this.setData({
                'formdata.posttime':time
            })
        }
        var postdata={
            author_id:this.data.userdata.id,
            author_name:this.data.userdata.username,
            author_avatar:this.data.userdata.avatar,
            container:this.data.formdata.container,
            posttime:this.data.formdata.posttime
        }
        console.log(postdata);
        wx.request({
          url: 'https://www.dongshengye.space/article/postArticle',
          method:'POST',
          data:postdata,
          success(e){
              console.log(e);
          }
        })
     },
     formReset(){
         this.setData({
             'formdata':''
         })
     }
})